import {getnewslist} from '../../utils/api'
Page({
  data: {
    chatList: [
      
    ]
  },
  //获取消息列表
  async getlist(){
    const {data:res} = await getnewslist()
    
    if(res.data.code == 200){
      this.setData({
        chatList:res.data.data
      })
    }else{
      wx.showToast({
        title: '网络超时，请重试',
        icon: 'none',
        duration: 2000,
        mask:true
      });
    }

  },
  //下拉事件
  async onPullDownRefresh() {
    const {data:res} = await getnewslist()
    if(res.data.code == 200){
     
      setTimeout(()=>{
          wx.stopPullDownRefresh();
      },1000)
      this.setData({
        chatList:res.data.data
      })
    }else{
      setTimeout(()=>{
        wx.stopPullDownRefresh();
      },1000)
      wx.showToast({
        title: '网络超时，请重试',
        icon: 'none',
        duration: 2000,
        mask:true
      });
    }
  },
  //跳转对话页
  onChatItemClick(e){
    
    wx.navigateTo({
      url: `/pages/newsinfo/newsinfo?id=${e.currentTarget.dataset.id}&&otherid=${e.currentTarget.dataset.otherid}&&gid=${e.currentTarget.dataset.gid}`,
    })
  },
  onLoad: function () {
    this.getlist()
    
  },
  onShow(){
    this.getlist()
  }
});